package com.mwy.future;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

//异步回调
//异步执行
//成功回调
//失败回调
public class FutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //利用异步任务执行线程任务
        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(()->{
            try {
                TimeUnit.SECONDS.sleep(2);
                System.out.println(Thread.currentThread().getName()+"执行");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        System.out.println("11111");

        completableFuture.get();

        System.out.println("2222");
    }
}
